#ifndef MONO_EVENT_EVENTLOOPTHREAD_H_
#define MONO_EVENT_EVENTLOOPTHREAD_H_

#include <mono/common/mutex.h>
#include <mono/common/cond.h>
#include <mono/common/thread.h>
#include <mono/base/config.h>
#include <mono/event/event_loop.h>
#include <functional>
#include <string>
#include <memory>

namespace mono {

class EventLoopThread{
public:
    typedef std::function<void(EventLoopPtr)> ThreadInitCallback;

    EventLoopThread(const ThreadInitCallback& cb = ThreadInitCallback(),
                            const std::string &name = std::string());
    ~EventLoopThread();
    EventLoopPtr start();
    EventLoopPtr getLoop() { return _loop; }
    void stop();
    

private:
    void threadFunc();
    MONO_DISSABLE_COPY_ASSIGN(EventLoopThread);
private:
    EventLoopPtr                      _loop;
    bool                              _exiting;
    mono::Mutex                       _mutex;
    mono::Cond                        _cond;
    mono::Thread                      _thread;
    ThreadInitCallback                _callback;
};

typedef std::shared_ptr<EventLoopThread> EventLoopThreadPtr;

}
#endif